<template>
  <el-form :model="dataForm" :rules="rules" @keyup.enter.native="submit()">
    <!-- //v-model.trim  修饰符 将输入内容前后的空格去掉 -->
    <el-form-item label="名称">
      <el-input v-model.trim="user.name" :disabled="upData" />
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model.trim="user.email" :disabled="upData" />
    </el-form-item>
    <el-form-item>
      <el-button v-if="upData" type="primary" @click="upData = !upData">修改个人信息</el-button>
      <el-button v-else type="primary" @click="submit">确认修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: ''
        }
      }
    }
  },
  data() {
    return {
      upData: true, // 修改开关
      dataForm: {
        name: '',
        email: ''

      },
      rules: {

      }
    }
  },
  methods: {
    submit() {
      this.upData = !this.upData
      this.$message({
        message: '用户信息修改成功',
        type: 'success',
        duration: 5 * 1000
      })
    }
  }
}
</script>
